const mongoose = require('mongoose');

const challengeSchema = new mongoose.Schema({
  title: { type: String, required: true },
  description: { type: String, required: true },
  category: { 
    type: String, 
    enum: ['transport', 'diet', 'energy', 'waste'],
    required: true 
  },
  difficulty: {
    type: String,
    enum: ['easy', 'medium', 'hard'],
    required: true
  },
  targetValue: { type: Number, required: true },
  unit: { type: String, required: true },
  points: { type: Number, required: true },
  co2eSavings: { type: Number, required: true },
  active: { type: Boolean, default: true },
  expirationDate: Date
}, { timestamps: true });

const userAchievementSchema = new mongoose.Schema({
  userId: { 
    type: mongoose.Schema.Types.ObjectId, 
    ref: 'User',
    required: true 
  },
  challengeId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Challenge',
    required: true
  },
  progress: { type: Number, default: 0 },
  completed: { type: Boolean, default: false },
  completedAt: Date
}, { timestamps: true });

module.exports = {
  Challenge: mongoose.model('Challenge', challengeSchema),
  UserAchievement: mongoose.model('UserAchievement', userAchievementSchema)
};